package com.qcby.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qcby.Constants;
import com.qcby.model.User;
import com.qcby.model.dto.UserQueryDto;
import com.qcby.model.resp.RespEntity;
import com.qcby.query.UserQuery;
import com.qcby.service.UserService;
import com.qcby.util.Page;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 用户查询
     */
    @ResponseBody
    @RequestMapping("/list")
    public String listAblum(UserQuery mq) {
        if (mq.getPageNo() == null) {
            mq.setPageNo(1);
        }
        System.out.println(mq.getPageNo());
        Page<User> page = userService.selectObjectByCondition(mq, "0");
//        model.addAttribute("page", page);
//        model.addAttribute("mq", mq);
        System.out.println(page);
        System.out.println(mq);
        return "success";
    }

    @ResponseBody
    @RequestMapping("/admin/query")
    public RespEntity<Page<User>> selectCondition(@RequestBody UserQueryDto userQueryDto) {
        return RespEntity.successCustomize(Constants.FLAG_200, "查询用户成功！", userService.query(userQueryDto));
    }

    @ResponseBody
    @RequestMapping("/admin/queryAll")
    public RespEntity<List<User>> listAll() {
        return RespEntity.successCustomize(Constants.FLAG_200, "查询用户成功！", userService.selectObjectAll());
    }

}
